import { createApp } from './main'
import Vue from 'vue'

const {App, router, store} = createApp()

if (window.__INITIAL_STATE__) {
  store.replaceState(window.__INITIAL_STATE__)
}

router.onReady(() => {
  App.$mount('#app')
})

// 全局执行,因为本地接管不会自动执行,也可以在组件上声明是否需要执行
Vue.mixin({
  beforeMount() {
    const { asyncData } = this.$options

    if (asyncData && !this.$options.stopAsyncData && !this.stopAsyncData) {
      this.dataPromise = asyncData({ 
        store, 
        route: router.currentRoute 
      })
    }
  }
})
